<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="jquery-1.7.2.js"></script>
<script type="text/javascript">
	function content_submit(){
		var f=document.refly_form;
		if(f.content.value==""){
			alert("내용을 입력하세요!");
			f.content.focus();
			return;
		}	
		f.submit();	
	}
	function modify_submit(){
		var f=document.modify_form;
		if(f.content.value==""){
			alert("내용을 입력하세요!");
			f.content.focus();
			return;
		}
		f.submit();
	}
	// 수정 텍스트박스 띄우기
	function modify_view(no){
 		var table="";
 		table+="<form action='board.do' name='modify_form' >";
		table+="<input type='hidden' name='command' value='modifyMiniRefly'>";
		table+="<input type='hidden' name='content_no' value=${requestScope.svo.bvo.content_no }>";
		table+="<input type='hidden' name='no' value="+no+">";
		table+="<table>";
		table+="<tr>";
		table+="<td width='90%'>";
		table+= "<textarea cols='35' rows='10' name='content'"; 
			table+="style='width:100%;";
				table+="height:60px;";
				table+="overflow-x:hidden;";
				table+="overflow-y:auto;";
				table+="font-size:9pt;";
				table+="resize:none;'>";
				table+=$("#modifyForm"+no).text();
				table+="</textarea>";
				table+="</td>";
				table+="<td valign='bottom'>";
				table+="<a onclick=modify_cancel('"+no+"') style='cursor: pointer;'><img src='img/board/modify_cancel.png'></a><br><img alt='덧글입력' src='img/board/minirefly_btn.png' onclick=modify_submit() style='cursor: pointer;'></a>";
				table+="</td>";
			table+="</tr>";
		table+="</table>";
		table+="</form>";
		$("#modifyForm"+no).html(table);
	}
	// 수정취소
	function modify_cancel(no){
		$("#modifyForm"+no).html($("#modifyForm"+no).text());
	}

	//이미지 크기 비율에 맞게 조절하는 함수
	function resize(img){
		   // 원본 이미지 사이즈 저장
		   var width = img.width;
		    var height = img.height;
		   // 가로, 세로 최대 사이즈 설정
		   var maxWidth =720;
		   var maxHeight = height; 
		   // 가로나 세로의 길이가 최대 사이즈보다 크면 실행  
		    if(width > maxWidth || height > maxHeight){
		      // 가로가 세로보다 크면 가로는 최대사이즈로, 세로는 비율 맞춰 리사이즈
		      if(width > height){
		          resizeWidth = maxWidth;
		          resizeHeight = Math.round((height * resizeWidth) / width);
		      // 세로가 가로보다 크면 세로는 최대사이즈로, 가로는 비율 맞춰 리사이즈
		       }else{
		          resizeHeight = maxHeight;
		          resizeWidth = Math.round((width * resizeHeight) / height);
		       }
		   // 최대사이즈보다 작으면 원본 그대로
		    }else{
		       resizeWidth = width;
		       resizeHeight = height;
		    }
		   // 리사이즈한 크기로 이미지 크기 다시 지정
		    img.width = resizeWidth;
		    img.height = resizeHeight;
		 }
	function refresh(){
		location.href="board.do?command=showContent&no=${requestScope.svo.bvo.content_no }&kind=${param.kind }&view=${param.view }";
	}
	function deleteContent(){
		var flag=confirm("게시물을 삭제하시겠습니까?");
		if(flag){
			location.href="board.do?command=deleteBoard&board_no=${requestScope.svo.bvo.board_no }&no=${requestScope.svo.bvo.content_no }&kind=${param.kind }&view=${param.view }";
		}
	}
	function deleteRefly(no){
		var flag=confirm("덧글을 삭제하시겠습니까?");
		if(flag){
			location.href="board.do?command=deleteMiniRefly&content_no=${requestScope.svo.bvo.content_no }&no="+no;
		}
	}
</script>
<!-- A=>게시글 링크 색상 -->
<style type="text/css"> 
A:link {text-decoration:none; color:black;} 
A:visited {text-decoration:none; color:black;} 
A:hover {text-decoration:underline; color:#5a5a5a;} 
</style>
</head>
<body>
	<c:if test="${sessionScope.vo==null }">
		<script type="text/javascript">
			alert("로그인 하신 후에 이용하실 수 있습니다!");
			location.href="member_view/login.jsp";
		</script>
	</c:if>
	<font size="2">
	<table cellpadding="5" id="top">
		<tr>
			<td align="right">
				<a href="board.do?command=list&board_no=${requestScope.svo.bvo.board_no }&kind=${param.kind }&view=${param.view }"><img alt="목록" border="0" src="img/board/list_btn.jpg"></a>
			</td>
		</tr>
		<tr>
			<td>
				<table  width="740" cellpadding="10"
					style="border-top:lightgray 1px solid;
								border-bottom:lightgray 1px solid;
								border-left:lightgray 1px solid;
								border-right:lightgray 1px solid;
								table-layout: fixed;" >
					<tr><!-- 제목|게시판명 	날짜|수정|삭제 -->
						<td width=69% style="padding-bottom: 0;"><b>${requestScope.svo.bvo.title }</b> | ${requestScope.svo.bvo.board_name }</td>
						<td align="right"
								style="padding-bottom: 0;">
							<font color="gray">${requestScope.svo.bvo.writeDate }</font>
							<c:if test="${requestScope.svo.bvo.id==sessionScope.vo.id ||sessionScope.vo.id=='admin' }"> <!-- 자신의 글만 수정 삭제 가능 -->
								 | <a href="board.do?command=updateView&board_no=${requestScope.svo.bvo.board_no }&no=${requestScope.svo.bvo.content_no }&kind=${param.kind }&view=${param.view }">수정</a>
								 | <a onclick="deleteContent()") style="cursor: pointer;">삭제</a>
							 </c:if>
						</td>
					</tr>
					<tr><td colspan="2" 
							style="padding-top: 0;
										padding-bottom: 0;"><img src="img/dottedline.png" width="710"></td></tr>
					<tr><!-- 작성자 -->
						<td colspan="2" style="padding-bottom: 0;">
							<b>${requestScope.svo.bvo.nick }(${requestScope.svo.bvo.id })</b>
						</td>
					</tr>
					<c:if test="${requestScope.svo.bvo.orgfilename!=null }">
					<tr><!-- 첨부파일 -->
						<td colspan="2" align="right" style="padding-top: 0;"><a href="board.do?command=download&newfilename=${requestScope.svo.bvo.newfilename}&orgfilename=${requestScope.svo.bvo.orgfilename}">
						<img src="img/board/icon-file.jpg">${requestScope.svo.bvo.orgfilename}</a></td>
					</tr>
					</c:if>
					<tr> <!-- 내용 -->
						<td colspan="2" valign="top">
							<c:if test="${param.kind=='picture' }"> <!-- 사진 게시판이면 사진 보여주기 -->
								<img src="upload/${requestScope.svo.bvo.newfilename }" onload="resize(this)"><br>
							</c:if>
							<div>${requestScope.svo.bvo.content}</div>
							<br><br><br><br><br><br><br>
						</td>
					</tr>
					<tr><!-- 덧글 조회수 -->
						<td colspan="2"><b><font color="#DB631F">덧글 ${fn:length(requestScope.svo.list) }개</font></b> | <b>조회수 ${requestScope.svo.bvo.count }</b></td>
					</tr>
					<tr><!-- 미니 리플 칸-->
						<td colspan="2" >
							<form action="board.do" name="refly_form" >
								<input type="hidden" name="command" value="writeMiniRefly">
								<input type="hidden" name="id" value=${sessionScope.vo.id }>
								<input type="hidden" name="nick" value=${sessionScope.vo.nick }>
								<input type="hidden" name="content_no" value="${requestScope.svo.bvo.content_no }">
								<input type="hidden" name="kind" value="${param.kind }">
								<input type="hidden" name="view" value="${param.view }">
							<table width="100%" cellpadding="2" bgcolor="#dcdcdc"><!-- 미니리플 회색테이블 -->
								<c:forEach var="rvo" items="${requestScope.svo.list }" varStatus="stat">
									<tr><!-- 작성자 날짜		수정 | 삭제 -->
										<td><b>${rvo.nick }</b> <font color=gray>${rvo.write_date }</font></td>
										<td align="right">
											<c:if test="${rvo.id==sessionScope.vo.id || sessionScope.vo.id=='admin'}"> <!-- 자신의 덧글만 수정 삭제 가능 -->
												<a onclick="modify_view('${rvo.refly_no }')" style="cursor: pointer;"><font color="#5a5a5a" size="2px">수정</font></a><font color="#5a5a5a" size="2px"> | </font>
												<a onclick="deleteRefly('${rvo.refly_no }')" style="cursor: pointer;"><font color="#5a5a5a" size="2px">삭제</font></a>
											</c:if>
										</td>
									</tr>
									<tr><!-- 미니리플내용 -->
										<td colspan="2">
											<div id="modifyForm${rvo.refly_no }">${rvo.content }</div>
											<hr color="lightgray">
										</td>
									</tr>
								</c:forEach>
								
								<tr><!-- 미니리플 입력창 -->
									<td width="90%">
										 <textarea cols="35" rows="10" name="content" 
												     style="width:100%;
												     			height:60px;
												     			overflow-x:hidden;
												     			overflow-y:auto;
												     			font-size:9pt;
												     			resize:none;">
</textarea>
									</td>
									<td valign="bottom">
										<img alt="덧글입력" src="img/board/minirefly_btn.png" onclick="content_submit()" style="cursor: pointer;">
									</td>
								</tr>
							</table>
							</form>
						</td>
					</tr>
				</table> 
			</td>
		</tr>
		<tr>
			<td align="right">
				<a href="board.do?command=writeView&board_no=${requestScope.svo.bvo.board_no }&kind=${param.kind }&view=${param.view }"><img alt="글쓰기" src="img/board/write_btn.jpg" border="0"></a>
				<a href="board.do?command=answerView&board_no=${requestScope.svo.bvo.board_no }&no=${requestScope.svo.bvo.content_no }&kind=${param.kind }&view=${param.view }"><img alt="답글" border="0" src="img/board/reply_btn.jpg"></a>
				<c:if test="${requestScope.svo.bvo.id==sessionScope.vo.id || sessionScope.vo.id=='admin'}"> <!-- 자신의 글만 수정 삭제 가능 -->
					<a href="board.do?command=updateView&board_no=${requestScope.svo.bvo.board_no }&no=${requestScope.svo.bvo.content_no }&kind=${param.kind }&view=${param.view }"><img alt="수정" border="0" src="img/board/modify_btn.jpg" ></a>
					<a onclick="deleteContent()") style="cursor: pointer;"><img alt="삭제"  border="0" src="img/board/delete_btn.jpg" ></a>
				</c:if>
				<a href="board.do?command=list&board_no=${requestScope.svo.bvo.board_no }&kind=${param.kind }&view=${param.view }"><img alt="목록" border="0" src="img/board/list_btn.jpg"></a>
			</td>
		</tr>
		<tr>
			<td align="right"><a href="#top"><img alt="top" src="img/board/top_btn.jpg"></a></td>
		</tr>
	</table>
	</font>
	<%--처리후 새로고침시 db 재입력 방지 flag --%>
	<% session.setAttribute("showContentFlag",true); %>
</body>
</html>